import java.util.PriorityQueue;
import java.util.concurrent.PriorityBlockingQueue;

class MyTask{
  private long time;
  private Runnable runnable;

    public MyTask(Runnable runnable,long time) {
        this.time = time;
        this.runnable = runnable;
    }

    public long getTime() {
        return time;
    }

    public Runnable getRunnable() {
        return runnable;
    }
    public void run(){
        runnable.run();
    }


}
public class MyTimer {

    private Thread thread=null;
    private PriorityBlockingQueue<MyTask> queue=new PriorityBlockingQueue<>();


    public MyTimer(){
        thread=new Thread(()->{
            try {
                MyTask task=queue.take();
                long nowtime=System.currentTimeMillis();
                if(nowtime< task.getTime()){
                    queue.put(task);
                }else{
                    task.run();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
    }
    public void shedule(Runnable runnable,long time){
          MyTask task=new MyTask(runnable,System.currentTimeMillis()+time);
          queue.put(task);
    }
}
